package com.jd.onlinequery.common.web;

import com.jd.onlinequery.common.utils.JasonUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Map;



public final class WebserviceInvokationParameter {

    private static final Logger logger = LoggerFactory.getLogger(WebserviceInvokationParameter.class);

    private String bizParam;
    
    public WebserviceInvokationParameter() {

    }

    public WebserviceInvokationParameter(String bizParam) {
        this.bizParam = bizParam;
    }

    public String getBizParam() {
        return bizParam;
    }

    public void setBizParam(String bizParam) {
        this.bizParam = bizParam;
    }

    public <T> T getJsonBizParamObject(Class<T> clazz) {
        if (StringUtils.isBlank(bizParam)) return null;
        T result = null;
        try {
            result = JasonUtil.fromJson(bizParam, clazz);
        } catch (IOException e) {
            logger.error("Unable to convert bizParam:'" + bizParam + "' to object, not a valid json format", e);
        }
        return result;
    }

    public Map<String, Object> getJsonBizParamMap() {
        if (StringUtils.isBlank(bizParam)) return null;

        Map<String, Object> result = null;
        try {
            result = JasonUtil.jsonToMap(bizParam);
        } catch (IOException e) {
            logger.error("Unable to convert bizParam:'" + bizParam + "' to Map, not a valid json format", e);
        }
        return result;
    }
}
